//==============================================================================
#ifndef _TANK_H_
#define _TANK_H_

#pragma once
#include "SceneObject.h"
#include "Scene.h"
#include "SDL_rotozoom.h"
#include "VisionCone.h"
#include "../../MultiplayerGame/GameEvent.h"
#include <iostream>

typedef std::list<SDL_Surface*> LISTSUR;
#define MAX_LIFE 100

//==============================================================================
namespace ui
{
class Tank : public SceneObject
{
public:
	Tank(void);
	Tank(int posX, int posY, string name);
	Tank(int posX, int posY, string name, int id);
	virtual ~Tank(void);
	void setRotation(bool flag);
	bool getRotation();
	void setSpeed(int speed);
	int getSpeed();
	void setShot(bool flag);
	bool getShot();
	void setAngularSpd(int angSpd);
	int getAngularSpd();
	int getBulletCount();
	void loadSurface() throw (SDL_Exception);
	void draw(SDL_Surface* s);
	COMPONENT_TYPE handleEvent(SDL_Event* event);
	void move(Component *s);
	void move(Component* s, VisionCone *v);
	void rotate();
	bool isMoving();
	void setTankBody();
	void setTankCannon();
	bool basicCollision(SDL_Rect r, int x, int y);
	bool optimizedCollision(SDL_Rect r, int angle, Point srcPivot);
	SDL_Rect getTankCannon(int posx, int posy);
	SDL_Rect getTankBody(int posx, int posy);
	void moveLeftOn();
	void moveRightOff();
	void moveRightOn();
	void moveLeftOff();
	void moveUpOff();
	void moveDownOff();
	void moveUpOn();
	void moveDownOn();
	void handleGameEvent(GameEvent* event);
	void decrementLife(int d);
	void bulletCollision();
	void mineCollision();
	void obstacleCollision();
	void setShowingName();
	void collisionEffect(SceneObject* so);

private:
	//void advance();
	int life;
	void retreat();
	void pushTankChangedEvent(void);
	private:
	SDL_Rect object_rect;
	SDL_Rect tankBody;
	SDL_Rect tankCannon;
	SDL_Surface *tmp;
	bool kPressedR,kPressedM,rotation;
	int speed;
	bool moving;
	bool shot;
	int bulletCount;
	LISTSUR* rotSurfaces;
	LISTSUR::iterator surfaces_it;
	int angularSpd;
	string eventMessage;
};
};
#endif
//==============================================================================